package jmm.thread.executors;

import java.util.concurrent.*;

/**
 * 自定义 MyThreadFactory ===》即线程名称自定义
 */
public class ThreadPoolExecutorUtil {

    public static ThreadPoolExecutor getNewThreadPool(int corePoolSize,
                                               int maximumPoolSize,
                                               long keepAliveTime,
                                               TimeUnit unit,
                                               BlockingQueue<Runnable> workQueue){
        return new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
                new MyThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
    }


    public static void main(String[] args) {
        BlockingQueue  blockingQueue  = new ArrayBlockingQueue(3);
        ThreadPoolExecutor newThreadPool = ThreadPoolExecutorUtil.getNewThreadPool(2,3,200,TimeUnit.MILLISECONDS,blockingQueue);

        newThreadPool.execute(()->{
            System.out.println(Thread.currentThread().getName() + "执行了");
        });

    }
}
